package cn.wd.user.controller;

import cn.wd.common.vo.R;
import cn.wd.user.domain.entity.BulletMsg;
import cn.wd.user.page.PageResult;
import cn.wd.user.qo.BulletMsgQueryObject;
import cn.wd.user.service.IBulletMsgService;
import cn.wd.user.vo.JsonResult;
import cn.wd.user.vo.ReportBulletMsg;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;

@RestController
@RequestMapping("/bulletMsg")
public class BulletMsgController {
    
    private final IBulletMsgService bulletMsgService;

    public BulletMsgController(IBulletMsgService bulletMsgService) {
        this.bulletMsgService = bulletMsgService;
    }

    @RequestMapping("/list")
    public R<Page<BulletMsg>> list(BulletMsgQueryObject qo) {
        return R.OK(bulletMsgService.ListBulletMsgPage(qo));
    }

    // 举报弹幕
    @RequestMapping("/reportBulletMsg")
    public R<?> saveOrUpdate(@RequestBody ReportBulletMsg reportBulletMsg) {
        bulletMsgService.reportBulletMsg(reportBulletMsg);
        return R.OK();
    }

    @RequestMapping("/saveOrUpdate")
    public R<?> saveOrUpdate(@RequestBody BulletMsg bulletMsg) {
        if (bulletMsg.getId() != null) {
            bulletMsgService.updateById(bulletMsg);
        } else {
            LocalDateTime now = LocalDateTime.now();
            bulletMsg.setVideoTime(now);
            bulletMsg.setReleaseTime(now);
            bulletMsgService.save(bulletMsg);
        }
        return R.OK();
    }

    @RequestMapping("/delete")
    public R<?> delete(Long id) {
        if (id == null) {
            return R.FAIL();
        }
        bulletMsgService.removeById(id);
        return R.OK();
    }
}
